package com.yanqu.road.server.manger.config;

import com.yanqu.road.entity.config.skill.SkillInfo;
import com.yanqu.road.entity.config.skinvolume.SkinEmbroideryConfigInfo;
import com.yanqu.road.entity.config.skinvolume.SkinVolumeConfigInfo;
import com.yanqu.road.logic.bussiness.config.SkinVolumeConfigBusiness;
import com.yanqu.road.server.TempMgr;

import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/4/26 21:13
 */
public class SkinVolumeMgr extends TempMgr {
    private static Map<Integer, SkinVolumeConfigInfo> skinVolumeConfigInfoMap;
    private static Map<Integer, SkinEmbroideryConfigInfo> skinEmbroideryConfigInfoMap;

    public static SkinVolumeConfigInfo getSkinVolumeConfigInfo(int volumeId) {
        return skinVolumeConfigInfoMap.get(volumeId);
    }

    public static SkinEmbroideryConfigInfo getSkinEmbroideryConfigInfo(int meter) {
        return skinEmbroideryConfigInfoMap.get(meter);
    }

    @Override
    public boolean reloadConfig() throws Exception {
        skinVolumeConfigInfoMap = SkinVolumeConfigBusiness.getSkinVolumeConfigInfo();
        skinEmbroideryConfigInfoMap = SkinVolumeConfigBusiness.getSkinEmbroideryConfigInfo();
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        reload();
        return true;
    }

    /**
     * 获取霓裳秘史刺绣修复技能效果加成
     * @param embroideryMeter
     * @param skillType
     * @return
     */
    public static int getSkillAddition(int embroideryMeter, int skillType, int occupation) {
        int addition = 0;
        for (SkinEmbroideryConfigInfo embroideryConfigInfo : skinEmbroideryConfigInfoMap.values()) {
            if (embroideryConfigInfo.getMeter() <= embroideryMeter) {
                SkillInfo skillInfo = SkillMgr.getSkillInfo(embroideryConfigInfo.getSkillId());
                if (skillInfo.getType() == skillType && (skillInfo.getParamList().get(2) == 0 || skillInfo.getParamList().get(2) == occupation)) {
                    addition += SkillMgr.getSkillAddition(skillInfo, 1);
                }
            }
        }
        return addition;
    }

    @Override
    public boolean stop() {
        return false;
    }
}
